System Commands


General-purpose commands that make your life with scripting easier are included in this section. System-oriented, these commands handle Windows Registry entries, file operations, Clipboard, installing of fonts, etc.

 

SysCommand("Command","Parameters")
Description
 


A bit unconventional command, having more functions inside of it, handles window-related operations and file copying.

First parameter is command-specific function. Depending on purpose, such function may require one or two arguments (set as second parameter).

Functions are not case-sensitive.


ResizeWindow
Description
 


Resizes program window to width and height values set as a second parameter. Both fixed and numerical variable parameters can be used.

First write width value:

640

...and after adding comma write height value:

480

Integrated with SysCommand:

SysCommand("ResizeWindow","640,480")



Example
 


**Resize program window to 320 (width) x 200 (height)

SysCommand("ResizeWindow","320,200")



MoveWindow
Description
 


Moves program window to x (horizontal) and y (vertical) values set as a second parameter.



Both fixed and numerical variable parameters can be used.

First write x (horizontal) value:

200

...and after adding comma write y (vertical) value:

150

Integrated with SysCommand:

SysCommand("MoveWindow","200,150")



Example
 


**Move program window to 300 (x), 420 (y)

SysCommand("MoveWindow","300,420")



CenterWindow
Description
 


Centers program window on the screen. No parameters required.




Example
 


**Center application window on screen

SysCommand("CenterWindow","")



AlwaysOnTop
Description
 


Puts program window on top of all opened windows and stays on top until some other window sets itself on top. No parameters required.



Example
 


**Set application window to 'always on top
'
SysCommand("AlwaysOnTop","")



NotAlwaysOnTop
Description
 


Opposite to previous SysCommand function, this one restores program window status to normal (not on top).



Example
 


**Restore application window to normal state

SysCommand("NotAlwaysOnTop","")



CopyFile
Description
 


Copies source file to destination file. Both files are specified through second command parameter.

Files are set as either:

a) folder path + file name, or
b) path macro + file name


First write source file:

<SrcDir>\MyProgram.ini

...and after adding comma write destination file:

<Windows>\MyProgram.ini

Integrated with SysCommand:

SysCommand("CopyFile","<SrcDir>\MyProgram.ini,
<Windows>\MyProgram.ini")

If directory structure doesn't exist, it will be created.

Both source and destination file names can differ.



Example
 


**Copy file c:\Project\Readme.txt to a:\backup\BackupReadme.txt

SysCommand("CopyFile","c:\Project\Readme.txt,
a:\backup\BackupReadme.txt")

 

Return()
Description
 


Terminates execution of currently running script.

Does not affect other scripts run through script timers.

Code Example
 

**Terminate script execution:
Return()

Additional Info
 

This command is often being used in for..next loops and if-statements to terminate further execution when some event occurs.

 

Break()
Description
 


Jump from For..Next loop. While Return() skip the execution of entire code after its usage, Break() only jump from For..Next loop, but execution of script continues after Next keyword.

Does not affect other scripts run through script timers.

Code Example
 

This code is useless, but it will show you how the Break() exactly works;) After its execution you will get 5 messages from loop i but only two messages from n loop...

maxloop=5
For i=1 To maxloop
  
Message("loop 1","i")
  
For n=1 To 10
    
If (n=3) Then
      
Break()
    
End
    
Message("loop 2","n")
  
Next n
Next i

...while The same code with Return() will show only one message from loop i and two messages from loop n. It's because Return() skips execution of entire code.

maxloop=5
For i=1 To maxloop
  
Message("loop 1","i")
  
For n=1 To 10
    
If (n=3) Then
      
Return()
    
End
    
Message("loop 2","n")
  
Next n
Next i

Additional Info
 

This command is often being used in for..next loops and if-statements to terminate further execution when some event occurs. Look at included break example.mbd

 

FileExist("Path","Variable")
Description
 


Checks if specified file exists and returns result using numerical variable.

First parameter sets a file to check, as either:

a) folder path + file name, or
b) path macro + file name


Second parameter sets numerical variable that will receive the result of file existence check. This means that you'll retrieve info from this variable (not give as command input) and create cases using if-statements.

Checking existence of file <SrcDir>\text.txt using FileCheck as numerical variable for result:

FileExist ("<SrcDir>\text.txt","FileCheck")

...will output check result through FileCheck numerical variable and there are only two available states:

  •   1 - file exists
  •   0 - file doesn't exist

Using if-statements to make decision depending on received result is a very natural choice:

if(FileCheck=1) then
  Message("File exists !","")
else
  Message("File does not exist.","")
end

Code Example
 

**Check for existence of win.ini in <Windows> folder and display
**message box if it does - otherwise exit project:

FileExist("<Windows>\win.ini","check" )
if (check=1) then
  Message("WIN.INI found. Goody.","")
else
  Exit()
end

 

FileString("SubString","Variable")
Description
 


Checks if specified string exists in <File> constant and returns result through a numerical variable. Use this command after Open File dialog box command OpenFile() , usually to check file extension.

First parameter sets string to search for, usually file extension:

.avi


Second parameter sets numerical variable that will receive result of a string existence check. This means that you'll retrieve info from this variable (not give as a command input) and create cases using if-statements.

Checking for .avi file extension using Type as a numerical variable for result looks like this:

FileString(".avi","Type")

Result is given through Type numerical variable and there are only two available states:

  •   1 - string exists
  •   0 - string doesn't exist


Of course, you don't have to search for file extension. Here we look for existence of "My Documents" folder in <File> path and result is put into FolderCheck numerical variable:

FileString("My Documents","FolderCheck")


Using if-statements to make decision depending on received result will make your scripting easier:

if(FolderCheck=1) then
  Message("Thanks for choosing My Documents !","")
else
  Message("Please choose My Documents folder.","")
end

Code Example
 

**Check Open File dialog box selection for MP3 file type and display
**message box if type doesn't match. Otherwise play MP3 file:

FileString(".mp3","check" )
if (check=1) then
  
PlaySound(" <File>")
else
  Message("Selected file is not MP3.","")
end

 

SaveVariable("Name","Variable")
Description
 


Saves contents of specified variable to Windows Registry.

Windows Registry is a database repository for information about a computer's configuration. The registry contains information that Windows continually references during operation - profiles for each user, programs installed on the computer, types of documents each program can handle, property settings for folders, hadware settins, etc.

You can use MMB's script commands SaveVariable and LoadVariable to handle Registry items under path assigned to your program:

HKEY_CURRENT_USER\Software\MMBPlayer\ ProjectEXE\ RegName


Let's split path above into sections.

HKEY_CURRENT_USER\Software\MMBPlayer\
Sets path to all MMB-made projects

ProjectEXE\

Represents file name of your compiled (EXE) project, without extension part. Program with file name MyMp3Player.exe would have this path assigned to it:

MyMp3Player\


RegName

Represents name you specified in Project Settings to serve as a Registry path identifier of your application:

Even when "Save Last Position in Registry" option is turned off, specified identifier will be used for SaveVariable and LoadVariable commands. So you can set identifier label and turn off "Save Last Position..." - label is stored and that's where your program will save and load Registry items.


Summary of MMB project Registry path story:

Having compiled program labeled ImageViewer.exe and Registry identifier label set to "Viewer" will result in this Registry path:

HKEY_CURRENT_USER\Software\MMBPlayer\ ImageViewer\ Viewer


Every item you save or load using SaveVariable and LoadVariable commands is put into section under path above.


OK, now you know WHERE items are saved. More important is knowing HOW to save items in Registry.


SaveVariable command saves Registry items using path pattern discussed above. Use first parameter to set Registry item label, for example:

User Settings

Second command parameter sets source variable for Registry item contents. You can use both string and numerical variables. MMB will recognize type of variable and save item either as a String (for string variables) or DWORD (for numerical variables).

You don't have to worry about that. Here's an example of saving string variable content (pass$) to Registry item labeled "Password":

pass$='MySecretPassword'
SaveVariable("Password","pass$")

And example of saving numerical variable content (HiPoints) to Registry item labeled "UserPoints":

HiPoints=4910
SaveVariable("UserPoints","HiPoints")

At the minimal level, you'll use saving of user's input at the application exit. Just make sure to use individual, original labels for Registry items.

On program startup, use LoadVariable command to retrieve saved values - just like all grownup programs do !

Code Examples
 

**Save contents of string variable EditBox$ (assigned to EditBox object)
**to Registry item labeled "EditBoxInput"

SaveVariable("EditBoxInput"," EditBox$")

**Save contents of numerical variable Width (containing screen width)
**to Registry item labeled "CurrentWidth"

Width=ScreenWidth()
SaveVariable("CurrentWidth","
Width")

**Save contents of numerical variable InstFlag, that serves as a flag
**for application install status, to Registry item labeled "Installed"

InstFlag=1
SaveVariable("Installed","
InstFlag")

Additional Info
 

MMB's Registry item handling commands work with fixed paths. To have full access to all Registry items, use system-related MMB PlugIns.

 

LoadVariable("Name","Variable")
Description
 


Loads item from Windows Registry, that was previously saved using SaveVariable command, and sets retrieved contents to either string or numerical variable.

Read more about Windows Registry and item paths in SaveVariable command description box.


To load Registry item, use first parameter to set Registry item label you want retrieve value from, for example:

User Settings

Second command parameter sets destination variable for retrieved Registry item content. You can use both string and numerical variables. Make sure to set correct variable type.

Here's an example of loading Registry item labeled "Password" to string variable pass$:

Load Variable("Password","pass$")

And example of loading Registry item labeled "UserPoints" to numerical variable HiPoints:

LoadVariable("UserPoints","HiPoints")


Loading of Registry items is usually performed at the program startup, to load user input saved during last program session.

Of course, you can load items whenever you want :)

Code Examples
 

**Load Registry item labeled "EditBoxInput" to string variable
** EditBox$ and display it in EditBox object:
LoadVariable("EditBoxInput"," EditBox$")
LoadText("EditBox","EditBox$")

**Load Registry item labeled "CurrentWidth" to numerical variable
**Width and display it using message box:
LoadVariable("CurrentWidth"," Width ")
Message("Saved screen width is: ","Width")

**Load Registry item labeled "Installed", that serves as a flag
**for application install status,
to a numerical variable InstFlag
**and make decision using if-statement:

LoadVariable("Installed","InstFlag ")
if (InstFlag=1) then
  NextPage()
else
  Message("Program is being run for the first time.","")
end

Additional Info
 

MMB's Registry item handling commands work with fixed paths. To have full access to all Registry items, use system-related MMB PlugIns.

 

InstallFont("Path")
Description
 


Users of MMB pay much attention to visual identity of their projects. In many cases, using standard font styles (pre-installed together with Windows) is not a satisfactory solution.

MMB helps in this case too - you only have to include font style in project distribution. Using InstallFont, MMB will check if user doesn't have specified font and if necessary - automatically install it.

On program exit, font will be uninstalled.

Only required parameter sets font file, as either:

a) folder path + file name, or
b) path macro + file name

Code Example
 

**Install font RoundStyle.ttf from <SrcDir> folder:
InstallFont("<SrcDir>\RoundStyle.ttf" )

 

Clipboard("Send/Get","Variable")
Description
 


Performs communication with Windows Clipboard (container that holds everything you copy/paste).

Use first parameter to specify Clipboard function you want to use:

  •  SEND : puts variable content to Clipboard
  •  GET : retrieves content from Clipboard

Second parameter sets either string or numerical variable that will be used either as source or destination of content.

It is recommended to use string variables for content retrieving.

Code Examples
 

**Send content of string variable put$ to Clipboard:
Clipboard("SEND" ,"put$")

**Send content of numerical variable ClickCount to Clipboard:
Clipboard("SEND" ,"ClickCount")

**Retrieve content of Clipboard to string variable content$ and
**display it in a message box:

Clipboard("GET" ,"content$")
Message("Clipboard says: ","content$"
)

Additional Info
 

You can only work with plain string and numerical data. Sending and retrieving of advanced content (bitmaps, objects) is not supported.


 

MMB Scripting Unleashed by Bokzy, 2003 :: All rights reserved :: http://www.bokzy.com